if [ -n "$1" ]; then
    data_date=$1
else
  data_date=`date -d '-1 days' +%F`
fi

dim_ads_platform_info_full="
WITH t1 AS (
    SELECT
        *
    FROM jtp_app_warehouse.ods_ads_platform_full
    WHERE dt = '${data_date}'
),t2 AS (
    SELECT
        *
    FROM jtp_app_warehouse.ods_ads_info_full
    WHERE dt = '${data_date}'
),t3 AS (
    SELECT
        *
    FROM jtp_app_warehouse.ods_platform_full
    WHERE dt = '${data_date}'
),t4 AS (
    SELECT
        *
    FROM jtp_app_warehouse.ods_ads_product
    WHERE dt = '${data_date}'
)
INSERT OVERWRITE TABLE jtp_app_warehouse.dim_ads_platform_info_full PARTITION (dt = '${data_date}')
SELECT
    t1.id,
    ad_id,
    ad_name,
    group_id,
    product_id,
    name,
    price,
    material_id,
    material_url,
    platform_id,
    platform,
    platform_alias_zh,
    create_time,
    cancel_time
FROM t1
LEFT JOIN t2 ON t1.ad_id = t2.id
LEFT JOIN t3 ON t3.id = t1.platform_id
LEFT JOIN t4 ON t4.id = t2.product_id;
"
/opt/module/spark/bin/beeline -u jdbc:hive2://node101:10001 -n bwie -e "
${dim_ads_platform_info_full}
"